import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';

@Injectable()
export class RequestCountMiddleware implements NestMiddleware {
  private requestCount = 0;
  // use
  public use = (req: Request, res: Response, next: () => void) =>{
    this.requestCount++;
    console.log(`Total Requests: ${this.requestCount}`);
    res.on('close', () => {
      this.requestCount--;
      console.log(`Total Requests: ${this.requestCount}`);
    });
    next(); 
  }
}
